package com.chen.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
//@Aspect
@Component
public class MyAspect6{
    //获取连接点信息
    @Before("execution(* com.chen.service.Impl.*.*(..))")
    public void before(JoinPoint joinPoint){
        //1.获取目标对象
        Object target = joinPoint.getTarget();
        log.info("获取目标对象: {}", target);
        //2.获取目标类
        String classname = joinPoint.getTarget().getClass().getName();
        log.info("获取目标类: {}", classname);
        //3.获取目标方法
        String methodname = joinPoint.getSignature().getName();
        log.info("获取目标方法: {}", methodname);
        //4.获取目标方法参数
        Object[] args = joinPoint.getArgs();
        log.info("获取目标方法参数:{}", Arrays.toString(args));
    }

    @Around("execution(* com.chen.service.Impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("around before.....");
        Object result = pjp.proceed();
        log.info("around after....");
        return result;
    }
}
